﻿MPT.addAction("clm_interest", function(_elm) {

    var body_jQ = $('.e_body', _elm);
    var no_data_jQ = $('.e_no_data', _elm);

    var addActionAdd = function(_interest_elm, _data) {
        var add_jQ = $('.e_add', _interest_elm);
        var uid = _data.USERID;
        var nickname = _data.NICKNAME;

        add_jQ.click(function() {
            var uinfo = { "uid": uid, "nickname": nickname };
            SocialUtil.displayAddDlg(uinfo);
        });
    };

    var initialize = function() {
        var data = { "pageNo": 1, "pageSize": 4 };
        Backend.findRecommendPerson(data, function(_resp) {
            if (Backend.pageBeanValidate(_resp)) {
                var results = _resp["results"];
                no_data_jQ.hide();
                body_jQ.empty().show();

                for (var i = 0; i < 4; i++) {
                    var _r = $.parseJSON(results[i]);
                    var uid = _r.USERID;
                    var nickName = _r.NICKNAME;
                    var avatarPath = Util.avatarPath(uid);
                    var spacePath = Util.spacePath(uid);
                    var html = [];

                    html.push('<dt><a href="' + spacePath + '" title="' + nickName + '">');
                    html.push('<img src="' + avatarPath + '" alt="' + nickName + '"></a></dt>');
                    html.push('<dd>');
                    html.push('<div class="btn1_24 add_friend"><a class="btn2_24 e_add" title="加为好友">加为好友</a></div>');
                    html.push('<a class="logo" href="' + spacePath + '" title="' + nickName + '">' + nickName + '</a>');
                    html.push('</dd>');

                    var interest_jQ = $(html.join(''));
                    addActionAdd(interest_jQ.get(), _r);
                    body_jQ.append(interest_jQ);
                }

            } else {
                no_data_jQ.html("没有可推荐的好友");
            }
        }, function() {
            no_data_jQ.html("数据加载错误");
        });
    };

    initialize();
});